// 封装axios的下载数据流转换成excel
export function DownLoadToExcel(url, data = {}, fileName) {
    fileName = fileName + '.xlsx'
    return new Promise((resolve, reject) => {
        axios
            .post(url, data, {
                responseType: 'blob'
            })
            .then(response => {
                const blob = new Blob([response.data], {
                    type: 'application/vnd.ms-excel'
                })
                if ('download' in document.createElement('a')) {
                    // 非IE下载
                    const elink = document.createElement('a')
                    elink.download = fileName
                    elink.style.display = 'none'
                    elink.href = URL.createObjectURL(blob)
                    document.body.appendChild(elink)
                    elink.click()
                    URL.revokeObjectURL(elink.href)
                    document.body.removeChild(elink)
                } else {
                    // IE10+下载
                    navigator.msSaveBlob(blob, fileName)
                }
                resolve()
            })
            .catch(error => {
                console.log(error)
                reject(error)
            })
    })
}